package leecode

func sortedArrayToBST(nums []int) (result *TreeNode) {
	var traversal func(nums []int, left, right int) (node *TreeNode)
	traversal = func(nums []int, left, right int) (node *TreeNode) {
		if left > right {
			return nil
		}
		mid := (left + right) >> 1
		node = &TreeNode{Val: nums[mid]}
		node.Left = traversal(nums, left, mid-1)
		node.Right = traversal(nums, mid+1, right)
		return node
	}
	return traversal(nums, 0, len(nums)-1)
}
